package wiki.kaizen.cloud.plugin.spring.scan.compent;

import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@EnableConfigurationProperties(ServerProperties.class)
public class CommonStartupCompent implements CommandLineRunner {
    private final ServerProperties prop;

    @Autowired
    public CommonStartupCompent(ServerProperties prop) {
        this.prop = prop;
    }

    @Override
    public void run(String... args) throws Exception {

        Integer port = prop.getPort();

        ServerProperties.Servlet servlet = prop.getServlet();

        String  finalPort = port!=null ? (":" + String.valueOf(port)) : "";
        String contextPath = servlet!=null&&!StringUtils.isEmpty(servlet.getContextPath())?servlet.getContextPath():"/";

        log.info("Application Started At http://127.0.0.1{}{}",finalPort,contextPath);

    }
}
